<?php

/**
 * @filename PassportAction.class.php 
 * @encoding UTF-8 
 * @author yuzhiyuan <307090870@qq.com>
 * @copyright copyright 2013 (c) Emagsoftware Technology Co., Ltd. All Rights reserved.
 * @license ……
 * @datetime 2013-6-22  12:02:42
 * @version 1.0
 * @Description
  */
class PassportAction extends Action {
    public function login(){
        if(session('uid')){
            redirect(__GROUP__);
        }
        $this->display();
    }
    public function doLogin(){
        if(!(IS_POST)) halt ('页面不存在！');
        if(I('code','','md5') != session('verify')) $this->error('验证码错误！');
        $udb = M('user');
        $accout = I('username');
        $password = md5(md5(I('password')));
        
        $user = $udb->where("email = '".$accout."' AND password = '".$password."' OR nickname = '".$accout."' AND password = '".$password."'")->find();
        if(!$user){
            $this->error('用户不存在或者密码错误！');
        }
        $uid = $user['id'];
        $data = array(
            'id' => $uid,
            'login_time' => time(),
            'login_ip' => get_client_ip(),
        );
        $udb->save($data);
        session('uid',$uid);
        session('nickname',$user['nickname']);
        redirect(__GROUP__);
        
    }
    
    public function logout(){
        session(null);
        $this->success('退出成功！', U(GROUP_NAME . '/Passport/login'));
    }
    
}